/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sql;

/**
 *
 * @author Micke
 */

import java.sql.*;

public class SQLConnector {

    public static final String DATABASE_USER = "DA5221_GRP10";
    public static final String DATABASE_NAME = "DA5221_GRP10";
    public static final String DATABASE_PASSWORD = "YabZnx";
    public static final String DATABASE_HOST = "194.47.47.18:3306";
    public static final String MYSQL_AUTO_RECONNECT = "autoReconnect";
    public static final String MYSQL_MAX_RECONNECTS = "maxReconnects";

    public static Connection getConnection() throws Exception {
        String driver = "com.mysql.jdbc.Driver";
        // load the driver
        Class.forName(driver);
        String dbURL = ("jdbc:mysql://" + DATABASE_HOST + "/" + DATABASE_NAME + "?user=" + DATABASE_USER + "&password=" + DATABASE_PASSWORD);

        String dbUsername = "DA5221_GRP10";
        String dbPassword = "YabZnx";

        java.util.Properties connProperties = new java.util.Properties();
        connProperties.put(DATABASE_USER, dbUsername);
        connProperties.put(DATABASE_PASSWORD, dbPassword);

        // set additional connection properties:
        // if connection stales, then make automatically
        // reconnect; make it alive again;
        // if connection stales, then try for reconnection;
        connProperties.put(MYSQL_AUTO_RECONNECT, "true");
        connProperties.put(MYSQL_MAX_RECONNECTS, "4");
        Connection conn = DriverManager.getConnection(dbURL, connProperties);
        return conn;
    }


}
